<template>
	<div>
		<van-nav-bar
		  title="标题"
		  left-text="返回"
		  
		  left-arrow
		  @click-left="$router.go(-1)"
		  
		/>
		<div id="l-map" style="height:300px"></div>
	</div>
</template>

<script>
	import {mapMutations} from 'vuex';
	export default {
		methods:{
			...mapMutations(['setLocation']),
		},
		mounted() {
			
			var map = new BMap.Map("l-map");
			    map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
			    map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用
			    map.centerAndZoom("北京", 12); // 初始化地图,设置城市和地图级别。
				this.getLocation()
		
		},
		methods:{
			getLocation(){
						var that = this;
						 let currentCity ='';
							console.log('获取位置');
								var geolocation = new BMap.Geolocation();
								geolocation.getCurrentPosition(function(r) {
									if (this.getStatus() == BMAP_STATUS_SUCCESS) {
										console.log(r.address);
										if (r.address.city) {
										    currentCity = r.address.city; //获取城市信息
											 
											 // this.$router.go(-1);
										    }
										// 初始化地图，设置中心点坐标和地图级别
										that.$store.commit('setLocation',currentCity);
									} else {
										alert('failed' + this.getStatus());
									}
									
								}, {enableHighAccuracy: true})
				
			}
		}
	}
</script>

<style>
</style>
